package org.web.base.domain.exception;

import lombok.Getter;
import lombok.Setter;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;


/**
 * 类ServiceException.java的实现描述：封装业务异常
 *
 * @author Luyl 2016年10月24日 上午10:23:00
 */
@SuppressWarnings("ALL")
@Setter
@Getter
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 1L;
    // 错误码
    private String errorCode;
    // 结果描述，用于排查问题
    private String description;
    // 参数
    private Map<String, Object> extendsValues = null;
    // 错误列表信息
    private List<String> errorList = null;

    public ServiceException(String errorCode, String description) {
        this (errorCode, description, null, null);
    }


    public ServiceException(String errorCode, String description, List<String> errorList, Map extendsValues) {
        this.errorCode = errorCode;
        this.extendsValues = extendsValues;
        this.description = description;
        this.errorList = errorList;
    }

    public ServiceException withExtendsValue(String key, Object model) {
        if (extendsValues == null) {
            setExtendsValues(new LinkedHashMap<>());
        }
        getExtendsValues().put(key, model);
        return this;
    }


    public ServiceException withErrorInfo(String errorInfo) {
        if (errorList == null) {
            setErrorList(new LinkedList<>());
        }
        getErrorList().add(errorInfo);
        return this;
    }

    public Map<String, Object> getExtendsValues() {
        return extendsValues;
    }

    public List<String> getErrorList() {
        return errorList;
    }

}
